package com.tfswue.qiu.service;

import com.tfswue.qiu.apis.UserClinet;
import com.tfswue.qiu.entity.Order;
import com.tfswue.qiu.entity.User;
import com.tfswue.qiu.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private UserClinet userClinet;
    public Order getOrderById(Integer id)
    {
        Order order = orderMapper.selectById(id);

        User user = userClinet.getUserById(order.getUserId());
        order.setUser(user);
        return order;
//        order.setUser(userClinet.getUserById(order.getUserId()));



    //不使用了, 使用feign
//        order.setUser(restTemplate.getForObject
//                //前提条件是与配置类里面的application一致
//                ("http://user-server/api/users/" + order.getUserId(), User.class));
//        return order;
    }
}
